class Solution {
public:
    vector<bool> vis;
    vector<vector<int>> g;

    void dfs(int cur)
    {
        vis[cur] = true;
        for(int i = 0;i < g[cur].size();i++)
        {
            int next = g[cur][i];
            if(vis[next]) continue;
            vis[next] = true;
            dfs(next);
        }
    }

    vector<int> remainingMethods(int n, int k, vector<vector<int>>& invocations)    {
        g.resize(n);
        vis.resize(n,false);
        vector<int> ans;
        for(int i = 0;i < n;i++) ans.push_back(i);

        for(int i = 0;i < invocations.size();i++)
        {
            int u = invocations[i][0];
            int v = invocations[i][1];
            g[u].push_back(v);
        }

        dfs(k);
        for(int i = 0;i < n;i++)
        {
            cout << vis[i] <<  " ";
        }

        for(auto& e : invocations)
        {
            int u = e[0];
            int v = e[1];
            if(!vis[u] && vis[v])
            {
                return ans;
            }
        }

        ans.clear();
        for(int i = 0;i < n;i++)
        {
            if(!vis[i]) ans.push_back(i);
        }
        return ans;
    }
};